/*     */ package com.zimbra.cs.account.ldap.upgrade;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Entry.EntryType;
/*     */ import com.zimbra.cs.account.ldap.LdapDIT;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.cs.ldap.IAttributes;
/*     */ import com.zimbra.cs.ldap.LdapClient;
/*     */ import com.zimbra.cs.ldap.LdapServerType;
/*     */ import com.zimbra.cs.ldap.LdapUsage;
/*     */ import com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor;
/*     */ import com.zimbra.cs.ldap.ZAttributes;
/*     */ import com.zimbra.cs.ldap.ZLdapContext;
/*     */ import com.zimbra.cs.ldap.ZLdapFilter;
/*     */ import com.zimbra.cs.ldap.ZLdapFilterFactory;
/*     */ import com.zimbra.cs.ldap.ZMutableEntry;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BUG_68190
/*     */   extends UpgradeOp
/*     */ {
/*     */   private static final String ATTR_NAME = "zimbraWebClientLoginURL";
/*     */   private static final String OLD_VALUE = "../../service/spnego";
/*     */   private static final String NEW_VALUE = "/service/spnego";
/*     */   
/*     */   void doUpgrade()
/*     */     throws ServiceException
/*     */   {
/*  40 */     ZLdapContext zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
/*     */     try {
/*  42 */       upgradeDomains(zlc);
/*     */     } finally {
/*  44 */       LdapClient.closeContext(zlc);
/*     */     }
/*     */   }
/*     */   
/*     */   Description getDescription()
/*     */   {
/*  50 */     return new Description(this, new String[] { "zimbraWebClientLoginURL" }, new Entry.EntryType[] { Entry.EntryType.DOMAIN }, "../../service/spnego", "/service/spnego", String.format("Upgrade attribute %s on all domains from \"%s\" to \"%s\"", new Object[] { "zimbraWebClientLoginURL", "../../service/spnego", "/service/spnego" }));
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private void upgradeDomains(ZLdapContext zlc)
/*     */   {
/*  60 */     String[] bases = this.prov.getDIT().getSearchBases(16);
/*  61 */     String query = "(&" + ZLdapFilterFactory.getInstance().allDomains().toFilterString() + "(" + "zimbraWebClientLoginURL" + "=" + "../../service/spnego" + ")" + ")";
/*     */     
/*     */ 
/*  64 */     upgrade(zlc, bases, query);
/*     */   }
/*     */   
/*     */   private void upgrade(ZLdapContext modZlc, String[] bases, String filter)
/*     */   {
/*  69 */     SearchLdapOptions.SearchLdapVisitor visitor = new Bug68190Visitor(this, modZlc);
/*     */     
/*  71 */     String[] attrs = { "zimbraWebClientLoginURL" };
/*     */     
/*  73 */     for (String base : bases) {
/*     */       try {
/*  75 */         this.printer.format("\n=== Searching LDAP: base = %s, filter = %s\n", new Object[] { base, filter });
/*  76 */         this.prov.searchLdapOnMaster(base, filter, attrs, visitor);
/*     */       }
/*     */       catch (ServiceException e) {
/*  79 */         this.printer.println("Caught ServiceException while searching " + filter + " under base " + base);
/*  80 */         this.printer.printStackTrace(e);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private static class Bug68190Visitor extends SearchLdapOptions.SearchLdapVisitor {
/*     */     private UpgradeOp upgradeOp;
/*     */     private ZLdapContext modZlc;
/*     */     
/*     */     Bug68190Visitor(UpgradeOp upgradeOp, ZLdapContext modZlc) {
/*  90 */       super();
/*  91 */       this.upgradeOp = upgradeOp;
/*  92 */       this.modZlc = modZlc;
/*     */     }
/*     */     
/*     */     public void visit(String dn, IAttributes ldapAttrs)
/*     */     {
/*     */       try {
/*  98 */         doVisit(dn, (ZAttributes)ldapAttrs);
/*     */       } catch (ServiceException e) {
/* 100 */         this.upgradeOp.printer.println("entry skipped, encountered error while processing entry at:" + dn);
/* 101 */         this.upgradeOp.printer.printStackTrace(e);
/*     */       }
/*     */     }
/*     */     
/*     */     public void doVisit(String dn, ZAttributes ldapAttrs) throws ServiceException {
/* 106 */       String curValue = ldapAttrs.getAttrString("zimbraWebClientLoginURL");
/*     */       
/* 108 */       this.upgradeOp.printer.println();
/* 109 */       this.upgradeOp.printer.println("Found entry " + dn);
/* 110 */       this.upgradeOp.printer.format("current value of %s is %s\n", new Object[] { "zimbraWebClientLoginURL", curValue });
/*     */       
/* 112 */       if ("../../service/spnego".equals(curValue)) {
/* 113 */         ZMutableEntry entry = LdapClient.createMutableEntry();
/* 114 */         entry.setAttr("zimbraWebClientLoginURL", "/service/spnego");
/* 115 */         this.upgradeOp.printer.format("updating %s to %s\n", new Object[] { "zimbraWebClientLoginURL", "/service/spnego" });
/* 116 */         this.upgradeOp.replaceAttrs(this.modZlc, dn, entry);
/*     */       } else {
/* 118 */         this.upgradeOp.printer.format("not updating %s\n", new Object[] { "zimbraWebClientLoginURL" });
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/upgrade/BUG_68190.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */